﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using WorkBasket.Data.Entities;

namespace WorkBasket.Infrastructure
{
    public class MyContext : DbContext
    {
        public MyContext ()
            : base("WorkBasketDB")
        {
            this.Configuration.ProxyCreationEnabled = false;
            //Database.SetInitializer<MyContext>(new DropCreateDatabaseAlways<MyContext>());
            this.Configuration.LazyLoadingEnabled = true;


        }
        public DbSet<Setting> Settings { get; set; }

        public DbSet<Email> Emails { get; set; }
        public DbSet<WBUser> WBUsers { get; set; }

        public DbSet<Workflow> Workflows { get; set; }
        public DbSet<Field> Fields { get; set; }
        public DbSet<Step> Steps { get; set; }
        public DbSet<Form> Forms { get; set; }
        public DbSet<ProcessVersion> ProcessVersions { get; set; }
        public DbSet<DisplayControl> DisplayControls {get;set;}
        public DbSet<ControlValidation> ControlValidations { get; set; }
        public DbSet<ControlType> ControlTypes { get; set; }
        public DbSet<Instance> Instances { get; set; }
        public DbSet<InstanceHistory> InstanceHistorys {get;set;}

        public DbSet<Unit> Units { get; set; }
        public DbSet<Group> Groups { get; set; }

        public DbSet<GroupMember> GroupMembers { get; set; }
        public DbSet<GroupProperty> GroupPropertys { get; set; }
        public DbSet<DomainUnit> DomainUnits { get; set; }

        public DbSet<Invite> Invites { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();//probably want to take this out once model is fully built
            modelBuilder.Configurations.Add(new WorkflowConfig());
            modelBuilder.Configurations.Add(new FieldConfig());
            modelBuilder.Configurations.Add(new VersionConfig());
            modelBuilder.Configurations.Add(new StepConfig());
            modelBuilder.Configurations.Add(new FormConfig());
            modelBuilder.Configurations.Add(new InstanceConfig());
            modelBuilder.Configurations.Add(new UnitConfig());
            modelBuilder.Configurations.Add(new GroupConfig());
            modelBuilder.Configurations.Add(new DomainUnitConfig());
            base.OnModelCreating(modelBuilder);
        }
    }
}
